package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dao.AdminDao;
import cn.edu.cqupt.cxcy.dto.AdminImpl;
import cn.edu.cqupt.cxcy.model.Fieldtype;
import cn.edu.cqupt.cxcy.util.Validate;


/**
 * 主页-【场地预约】
 * @author Dancer-mno
 * @date 2015年10月17日
 */
@SuppressWarnings("serial")
public class AdminNavCdyy extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String pjax_back = "$(function(){$(\"a.turn_pjax[href='admin/link_addCdyy']\").trigger('click');});";
		if(req.getHeader("x-pjax") == null || req.getHeader("x-pjax").equals("null")) {
			req.setAttribute("pjax_back", pjax_back);
			req.getRequestDispatcher("manager.jsp").forward(req, resp);
		} else if (req.getHeader("x-pjax").equals("true")) {
			int status = Validate.stringIsNO(req.getParameter("status"))?Integer.parseInt(req.getParameter("status")):255; //类别
			AdminDao admin = new AdminImpl();
			List<Object> cdlist = admin.cDList( AdminDao.CDYY_PAGING, 1, 255, status);
			double count  = admin.countCd(null, 255);
			List<Fieldtype> field = admin.fieldType();
			req.setAttribute("count", (int)Math.ceil(count / AdminDao.CDYY_PAGING));
			req.setAttribute("cdlist", cdlist);
			req.setAttribute("field", field);
			req.getRequestDispatcher("nav_cdyy.jsp").forward(req, resp);
		}
	}
}
